<template>
	<el-drawer title="快捷流程设置" v-model="visible" :size="600" destroy-on-close @closed="$emit('closed')">
		<el-container v-loading="loading">
			<el-main>
				<el-transfer
					filterable
					:filter-method="filterMethod"
					filter-placeholder="请输入流程名称"
					:titles="['备选流程', '已选流程']"
					v-model="form.flowId"
					:props="flowProps"
					target-order="push"
					:data="flowList">
				</el-transfer>
				<el-footer style="text-align: center;">
					<el-button @click="visible=false">关闭</el-button>
					<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
				</el-footer>
			</el-main>
		</el-container>
	</el-drawer>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	components: {},
	data() {
		return {
			loading: false,
			flowList: [],
			form: {
				flowId: []
			},
			visible: false,
			isSaveing: false,
			flowProps:{key:'value',label:'label'},
			filterMethod(query, item) {
				return item.label.indexOf(query) > -1;
			},
		}
	},
	mounted() {
		this.getFlowInRoleForBpmQuick();
	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this;
		},
		async submit() {
			this.isSaveing = true;
			let flowIdStr=this.form.flowId.join(",")
			var res = await this.$API.bpm.bpmQuick.setBpmQuick.post({flowIdStr:flowIdStr});
			if (res.code == 200) {
				this.$emit('success')
				this.visible = false;
				this.$message.success("操作成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
				this.isSaveing = false;
			}
		},
		async getFlowInRoleForBpmQuick() {
			let res = await this.$API.bpm.bpmQuick.getFlowInRoleForBpmQuick.get();
			if (res.code == 200) {
				this.flowList = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//表单注入数据
		setData(data) {
			if(data!==undefined)
			{
				data.forEach(item => {
					this.form.flowId.push(item.value);
				});
			}
		},
	}
}
</script>

<style>
</style>
